<include file="Common:header" />
<body>
<table><tr>
<td width="160" valign="top" bgcolor="#eaeaea"><include file="Common:adminpanel" /></td>

<td valign="top" >
<div>
<h1>已发货订单</h1>
<form method="post" id="tradeSearch" name="tradeSearch"  action="<{:U('tsearch')}>">
<table width="100%" cellspacing="1" cellpadding="3" border="0">
<tr>
	<td>搜索订单：
	  <select name="field" id="field">
	    <option value="receiver_name">收货人姓名</option>
	    <option value="buyer_nick">买家昵称</option>
	    <option value="receiver_mobile">收货人的手机号码</option> 	
	    <option value="receiver_phone">收货人的电话号码</option>
	    <option value="tplid">快递模板</option>
	    </select>
	  
	  <input type="text" id="k" name="k" value="<{$map[k]}>">
	  <select name="tplid" id="tplid" style="display:none"><option value="0">选择快递</option><{$tploptions}></select>
	  <select name="seller_nick" id="seller_nick">
	  <option value="">选择卖家</option>
	  <?php
	  if( $sellers ) {
			foreach( $sellers as $seller ) {
				$slt = $map[seller_nick] == $seller ? ' selected' : '';
				echo '<option value="'. $seller .'"'.$slt.'>'. $seller .'</option>';
			}
		
		}
	  ?>
	  </select>
	  &nbsp;
	  <select name="timeflag" id="timeflag">
	  <option value='sysaddtime' <?php echo $map['timeflag'] == 'sysaddtime' ? 'selected' : '' ?>>订单日期</option>
	  <option value='sysprinttime' <?php echo  $map['timeflag'] == 'sysprinttime' ? 'selected' : '' ?>>打印日期</option>
	  </select> 
	  <input id="d12" type="text" name="time" value="<{$map[time]}>" />
	  <img onclick="WdatePicker({el:'d12'})" src="<{:__PUBLIC__}>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
	  <input type="hidden" name="status" id="status" value="<{$status}>" />
	  <input type="submit" name="submit" id="submit" value="搜索" />	  </td>
	<td>
	  </td>
</tr>
</table>
</form>
<table width="100%" cellspacing="1" cellpadding="3" border="0">
<tr class="header">
<th width="100" height="30">订单号</th>
<th>卖家帐号</th>
<th>买家帐号</th>
<th>收货地址</th>
<th width="">卖家备注<br>
  买家留言</th>
<th width="130">商品信息</th>
<th width="80" align="center">快递</th>
<th align="center">订单金额<br>
  总成本</th>
<th align="center">运单号</th>
<th width="100" align="center">提交时间<br>打印时间</th>
<th width="70" align="center">操作</th>
<th width="60" align="center">打印</th>
</tr>
<php>
if( $tradelist ) {
	
	foreach( $tradelist as $trade ) {
		$ordersinfo = '';
		$orders = unserialize( $trade['orders'] );		
		foreach(  $orders['order'] as $t=>$order ){
			$ordersinfo .= '<div>'. ($t+1).'.'. $order['outer_sku_id'] .'('.$order['num'] .'件)</div>';
		}
		$company = D('Company')->where("id={$trade['syscomid']}")->find();
		$tprint = U("tprint?tid={$trade['tid']}");
		$tradeflag = tradeflag( $trade['seller_flag'] );
		$tradefeedback = D('Tradefeedback')->where("tid={$trade['tid']}")->find();
		$tradeNum = $_GET['field'] == 'buyer_nick' ? '' : D('Trade')->getTradeCountByBuyer( $trade['buyer_nick'], 2 );	//按买家查看订单数
		echo '<tr class="row">
		<td height="50">'. $trade['tid']. '</td>
		<td>'. $trade['seller_nick'] . '</td>
		<td>'. $trade['buyer_nick'] .' <img src="'.__PUBLIC__ . '/images/c.png" onclick="window.location.href=\\''. U("Trade/tsearch?status=2&field=buyer_nick&k={$trade['buyer_nick']}") .'\\'" />&nbsp;<b style="color:red">'. $tradeNum .'</b><br>'. contacttuser( $trade['buyer_nick'] ) . '</td>
		<td>'. $trade['receiver_name'] .','. $trade['receiver_mobile'] . ','. $trade['receiver_phone'] .',' . $trade['receiver_state'] .', '. $trade['receiver_city']. ' '. $trade['receiver_district'] .','. $trade['receiver_address'] .','. $trade['receiver_zip'] . '</td>
		<td><span style="color:red">'. $tradeflag . ' '. $trade['seller_memo'] . '</span><br><span style="color:blue">' . $trade['buyer_message'] .'</span></td>
		
		<td>'. $ordersinfo .'</td>
		<td align="center">'. $company['name'] .'</td>
		<td align="center">' .$trade['payment']. '/'. $trade['syscost'] .' </td>
		<td align="center">' .$trade['out_sid']. '</td>
		<td align="center">' .$trade['sysaddtime']. '<br>'.$trade['sysprinttime'].'</td>
		<td width="70" align="center">';
		if( $tradefeedback  ) {
			echo '<img src="'. __PUBLIC__. '/images/talk_on.png" id="toTalk_'. strval($trade['tid']) .'" style="cursor:pointer" alt="'. strval($trade['tid']) .'" title="'. U("Trade/tfeedback?tid={$trade['tid']}") .'" />';
		} else {
			echo '<img src="'. __PUBLIC__. '/images/talk_off.png" id="toTalk_'. strval($trade['tid']) .'" style="cursor:pointer" alt="'. strval($trade['tid']) .'" title="'. U("Trade/tfeedback?tid={$trade['tid']}") .'" />';
		}
		echo '&nbsp; ';
		if( $trade[systodo] ) {
			echo '<img src="'. __PUBLIC__. '/images/do_on.png" id="todo_'. strval($trade['tid']) .'" style="cursor:pointer"  alt="'. strval($trade['tid']) .'" />';
		}else {
			echo '<img src="'. __PUBLIC__. '/images/do_off.png" id="todo_'. strval($trade['tid']) .'" style="cursor:pointer" alt="'. strval($trade['tid']) .'" />';
		}
		echo '</td>
		<td align="center"><a href="'. $tprint. '" target="_blank">打印</a></td>
		</tr>';
	} 
}
//[<a href="'. U("tfeedback?tid={$trade['tid']}") .'">待处理</a>]
</php>
<tr class="row">
<td colspan="12" height="30" align="center"><div><{$page}></div></td>
</tr>
</table>
</div>
</td>
</tr></table>


<script>
$(document).ready(function(){
	$("select[id^='company_']").bind('change', function(){
		var tplid = $(this).val();
		var tid   = $(this).attr( 'alt' );
		$.post ( '<{:U('Index/price')}>', { trade : $("#tradedata_" + tid ).val() , tplid: tplid }  ,
			function(data){
				if( 1 == data['status'] ) {
					$('#chengben_'+tid).html( data['data']['cost'] );	
				} else {
					alert( data['info']);
				}
			 	
			}	
		); 
	});
	
	
	
	$("input[id^='btnTradeSend']").bind('click', function(){
		var tid = $(this).attr( 'alt' );
		var company_code = $( '#company_code_'+tid ).val();
		var out_sid = $( '#out_sid_'+tid ).val();
		if( out_sid == null || '' == out_sid ) {
			alert('填写运单号');
			$( '#out_sid_'+tid ).focus();
			return false ;
		}
		$.post( '<{:U('Trade/tsend')}>' , {
				tid : tid, company_code: company_code ,  out_sid : out_sid 
			}, 
			function(data){
				if( 1 == data['status'] ){
					alert( data['info'] );
				}else {
					alert('提交失败 '+ data['info'] );	
				}
				
			} 
		);
	} );
	
	
	
	
	//搜索
	$("#field").val( '<{$map[field]}>' );
	if(  $("#field").val() == 'tplid' ){
		$("#tplid").show();	
		$("#k").hide();
		
		$("#tplid").val( <{$map[tplid]}> );
	}else {
		$("#tplid").hide();
		$("#k").show();
	}
	
	$("#field").bind("change", function(){
		if( $(this).val() == 'tplid' ){
			$("#tplid").show();	
			$("#k").hide();
		}else {
			$("#tplid").hide();
			$("#k").show();
		}
		
		
	});
	
	
	//待处理	
	$("img[id^='todo_']").bind( 'click', function() {
		var tid = $(this).attr( 'alt' );
		var _this  = $(this);
		$.post( '<{:U('Trade/ttodo')}>' , {
			tid : tid
		}, 
		function(data){
			if( 1 == data['status'] ){
				if( 1 == data['data'] ) {
					_this.get(0).src ='<{:__PUBLIC__}>/images/do_on.png';
				}else {
					_this.get(0).src ='<{:__PUBLIC__}>/images/do_off.png';
				}
				//alert( data['info'] );
				//_this.attr('disabled', 'disabled');
			}else {
				alert('提交失败 '+ data['info'] );	
			}
			
		} 
	);
	} );
	
	$("img[id^='toTalk_']").bind( 'click', function(){
		
		var _this = $(this);
		var tid = _this.attr('alt');
		var url = _this.attr('title');
		
		art.dialog.open( url , {
			id: 'fedbbackID',
		    title: '待处理',
		    yesFn: function(){
		    },
		    noFn: function(){
		    }
		});
		
	} )
	
	
});
</script>
</body>
</html>